//
//  JiaoYanViewController.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/3.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "JiaoYanViewController.h"
#import "SYWanChengTableViewCell.h"
#import "SYShiXunHeaderView.h"
#import "SYJiaoYanModel.h"
#import "SYTitleTableViewCell.h"
#import "SYJiaoYanTitleTableViewCell.h"
#import "SYDetailsXinDeTableViewCell.h"
#import "SYAddJiLuView.h"//添加记录
#import "SYTiJiaoChengGuoView.h"//提交成果
#import "SYJiaoYanChuangJianView.h"//创建小组
#import "SYFenPeiJiangLiView.h"//积分分配

@interface JiaoYanViewController () <UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) SYTopView *topView;
@property (nonatomic, strong) UIButton *addBtn;//添加按钮
@property (nonatomic, strong) UITableView *curTableView;
@property (nonatomic, strong) SYAddJiLuView *jiluView;//
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) SYShiXunHeaderView *headerView;
@property (nonatomic, strong) SYTiJiaoChengGuoView *tijiaochenguoView;//提交成果
@property (nonatomic, strong) SYJiaoYanChuangJianView *chuangjianView;//创建
@property (nonatomic, strong) SYFenPeiJiangLiView *jiangliView;//分配奖励

@end

@implementation JiaoYanViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"------------走了");
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
    [self initSubView];
    
    
}

- (void)initSubView {
    self.dataArr = [[SYJiaoYanModel alloc] monishuju];
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(45);
    }];
    
    [self.view addSubview:self.addBtn];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(25);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(40);
    }];
    
    //表
    [self.view addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom).offset(0);
        make.left.equalTo(self.view).offset(14);
        make.right.equalTo(self.view.mas_right).offset(-14);
        make.bottom.equalTo(self.view.mas_bottom).offset(-14);
    }];
    
}


#pragma mark - tab
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    SYJiaoYanModel *jyModel = self.dataArr[section];
    return jyModel.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYJiaoYanModel *jyModel = self.dataArr[indexPath.section];
    SYjiaoYanListModel *listModel = jyModel.dataArr[indexPath.row];
    
    if (listModel.type == SYJiaoyanModelTypeJiaoYanJiLu || listModel.type == SYJiaoyanModelTypeJiaoYanChengGuo) {
        return 60;
    } else {
        return 44;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 223+40+40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYJiaoYanModel *jyModel = self.dataArr[indexPath.section];
    SYjiaoYanListModel *listModel = jyModel.dataArr[indexPath.row];
    if (listModel.type == SYJiaoyanModelTypeXiaoZu) {//小组成员
        SYWanChengTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYWanChengTableViewCell" forIndexPath:indexPath];
        UIColor *color = nil;
        if (indexPath.row%2) {
            color = [UIColor whiteColor];
            
        } else {
            color = [UIColor colorWithHexString:@"F8F8F8"];
        }
        wCell.selectionStyle = UITableViewCellSelectionStyleNone;
        //    wCell.delegate = self;
        [wCell incomingDataInteger:indexPath.section backColor:color];
        return wCell;
    } else if (listModel.type == SYJiaoyanModelTypeJiaoYanJiLu || listModel.type == SYJiaoyanModelTypeJiaoYanChengGuo) {//教研记录  教研成果
        SYTitleTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYTitleTableViewCell" forIndexPath:indexPath];
        wCell.selectionStyle = UITableViewCellSelectionStyleNone;
        __weak typeof(self) weakSelf = self;
        wCell.block = ^(SYTitleTableViewCellType type) {
            [weakSelf selectBtnStaus:type];
        };
        [wCell titleTableViewCellModel:listModel cont:nil];
        return wCell;
    } else if (listModel.type == SYJiaoyanModelTypejyTitle || listModel.type == SYJiaoyanModelTypecgTitle) {
        SYJiaoYanTitleTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYJiaoYanTitleTableViewCell" forIndexPath:indexPath];
        wCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return wCell;
        
    } else {
        SYDetailsXinDeTableViewCell *detailsCell = [tableView dequeueReusableCellWithIdentifier:@"SYDetailsXinDeTableViewCell" forIndexPath:indexPath];
        detailsCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [detailsCell detailsXinDeTableViewType:SYDetailsTypeXinDe];
        return detailsCell;
    }
    
    
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    _headerView = [[SYShiXunHeaderView alloc] init];
    [view addSubview:_headerView];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(view).offset(14);
        make.right.equalTo(view).offset(-14);
        make.bottom.equalTo(view.mas_bottom).offset(0);
    }];
    if (section == 0) {
        [_headerView shixunHeaderViewType:SYShiXunHeaderViewTypeJiaoYanWeiWanCheng index:0];
    } else {
        [_headerView shixunHeaderViewType:SYShiXunHeaderViewTypeDefault index:1];
    }
    __weak typeof(self) weakSelf = self;
    _headerView.block = ^(SYShiXunHeaderSelectType type) {
        if (type == SYShiXunHeaderSelectTypeTiJiaoChengGuo) {//提交成果
            [weakSelf showTiJiaoChengGuoView];
        } else if (type == SYShiXunHeaderSelectTypeGuanLiChengYuan) {//管理成员
            [weakSelf showGuanLiChengYuanView];
        }
    };
    
    return view;
}
//提交成果
- (void)showTiJiaoChengGuoView {
    _tijiaochenguoView = [[SYTiJiaoChengGuoView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20)];
    [self.view addSubview:_tijiaochenguoView];
    
    [UIView animateWithDuration:kAnimate animations:^{
        self.tijiaochenguoView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20);
    }];
}
//管理成员
- (void)showGuanLiChengYuanView {
    [self addBtnClick];
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view);
        make.left.equalTo(view.mas_left).offset(14);
        make.right.equalTo(view.mas_right).offset(-14);
        make.height.mas_equalTo(20);
    }];
    return view;
}
//教研记录，积分的添加，积分点击事件
- (void)selectBtnStaus:(SYTitleTableViewCellType)type {
    if (type == SYTitleTableViewCellTypeJiFen) { //积分
        
        
        
    } else {//添加记录
        _jiluView = [[SYAddJiLuView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20)];
        [self.view addSubview:_jiluView];
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:kAnimate animations:^{
            weakSelf.jiluView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20);
        }];
    }
}



#pragma mark - 添加小组
- (void)addBtnClick {
    _chuangjianView = [[SYJiaoYanChuangJianView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20)];
    [self.view addSubview:_chuangjianView];
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:kAnimate animations:^{
        weakSelf.chuangjianView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.frame), kScreen_HEIGHT-20);
    }];
}

- (SYTopView *)topView {
    if (!_topView) {
        _topView = [[SYTopView alloc] init];
        _topView.titleLab.text = @"教研";
    }
    return _topView;
}
- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [_addBtn setImage:[UIImage imageNamed:@"add_teach"] forState:UIControlStateNormal];
        //        _addBtn.hidden = YES;
        _addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_addBtn setTitleColor:TITLECOLOR forState:0];
        [_addBtn setTitle:@" 创建小组" forState:UIControlStateNormal];
    }
    return _addBtn;
}
- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _curTableView.backgroundColor = [UIColor whiteColor];
        [_curTableView registerCellWithClassNames:@[@"SYWanChengTableViewCell"]];
        [_curTableView registerCellWithNIbNames:@[@"SYTitleTableViewCell",@"SYJiaoYanTitleTableViewCell",@"SYDetailsXinDeTableViewCell"]];
    }
    return _curTableView;
}

//- (SYJiaoYanChuangJianView *)chuangjianView {
//    if (!_chuangjianView) {
//        _chuangjianView = [[SYJiaoYanChuangJianView alloc] init];
//    }
//    return _chuangjianView;
//}


@end














